﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using TextToHTMLExtensionInterfaces;

namespace TextToHTML.Components
{
    /// <summary>
    /// Parses for http://blahblahblah in the text, and returns URI objects.
    /// </summary>
    [Export(typeof(IParseText))]
    class HTTPParser : IParseText
    {
        public TextRun[] FindTextToReplace(string text)
        {
            List<TextRun> results = new List<TextRun>();
            int httpStart = text.IndexOf("http://");
            if (httpStart >= 0)
            {
                int nextSpace = text.IndexOf(" ", httpStart);
                if (nextSpace < 0)
                    nextSpace = text.Length;
                TextRun r = new TextRun() { Start = httpStart, Length = nextSpace - httpStart };
                r.whatItIs = new Uri(text.Substring(r.Start, r.Length));
                results.Add(r);
            }
            return results.ToArray();
        }
    }
}
